/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.upc.sad.util;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author aalanya
 */
public class ToolSql
{

       public static String buildProcedureCall(String packageName, String procedureName, int paramCount)  
    {
        StringBuffer sb = new StringBuffer("{call "+packageName+"."+procedureName+"(");
        for (int n = 1; n <= paramCount; n++) 
        {
            sb.append("?");
            if (n < paramCount) sb.append(",");
        }
        return sb.append(")}").toString();
    }
    
    public static void close(ResultSet rs, Statement s, CallableStatement cs, Connection con )
    throws  SQLException
    {
        try 
        { 
          if (rs != null) rs.close(); 
        } catch (Exception e) {
            e.printStackTrace();
        }
        try 
        { 
          if (s != null) s.close(); 
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        try 
        { 
          if (cs != null) cs.close(); 
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }  
        try 
        { 
          if (con != null) con.close();
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }

    public static void close(ResultSet rs, PreparedStatement ps, CallableStatement cs, Connection con )  throws  SQLException
    {
        try 
        { 
          if (rs != null) rs.close(); 
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        try 
        { 
          if (ps != null) ps.close(); 
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        try 
        { 
          if (cs != null) cs.close(); 
        } 
        catch (Exception e) 
        {
          e.printStackTrace();
        }    
        try 
        { 
          if (con != null) con.close();
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }           
    }

    public static void close(ResultSet rs, Statement s, CallableStatement cs )  throws  SQLException
    {
        try 
        { 
          if (rs != null) rs.close(); 
        } 
        catch (Exception e)
        {
            e.printStackTrace();
        }
        try 
        { 
          if (s != null) s.close(); 
        } 
        catch (Exception e) {
            e.printStackTrace();
        }
        try 
        { 
          if (cs != null) cs.close(); 
        } 
        catch (Exception e) {
            e.printStackTrace();
        }  
         
    }

    public static void close(ResultSet rs, PreparedStatement ps, CallableStatement cs )  throws  SQLException
    {
        try 
        { 
          if (rs != null) rs.close(); 
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        try 
        { 
          if (ps != null) ps.close(); 
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        try 
        { 
          if (cs != null) cs.close(); 
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }    
    }
/*
    public static String getLikeCons( String fieldValue )
    {
      if( UCadena.esBlankStringValidaVacio( fieldValue ) )
        return "%";
			
      return "%"+fieldValue.toUpperCase()+"%";
    }
*/
}
